export default {

  trlTime(day = 1) { //自定义请求时间
    let time: any = new Date()
    const satrtTime = time.valueOf() - 1000 * 3600 * 24 * day
    time =
      (time.getFullYear() < 10 ? '0' + time.getFullYear() : time.getFullYear()) +
      '-' +
      (time.getMonth() + 1 < 10 ? '0' + (time.getMonth() + 1) : (time.getMonth() + 1)) +
      '-' +
      (time.getDate() < 10 ? '0' + time.getDate() : time.getDate()) +
      ' ' +
      (time.getHours() < 10 ? '0' + time.getHours() : time.getHours()) +
      ':' +
      (time.getMinutes() < 10 ? '0' + time.getMinutes() : time.getMinutes()) +
      ':' +
      (time.getSeconds() < 10 ? '0' + time.getSeconds() : time.getSeconds())
    //   console.log(time)

    let date:any = new Date(satrtTime)
    const YY = date.getFullYear() + '-'
    const MM =
      (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
    const DD = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
    const hh =
      (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
    const mm =
      (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) +
      ':'
    const ss =
      date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
    // return ;
    date = YY + MM + DD + ' ' + hh + mm + ss

    return [ date, time ]

  },

  getType(date) {
    const timestamp1 = new Date(date[0]).valueOf()
    const timestamp2 = new Date(date[1]).valueOf()
    let typeValue
    const timeDiffer = (timestamp2 - timestamp1) / (1000 * 3600 * 24)

    if (timeDiffer >= 1 && timeDiffer <= 14) {// 小于 等于14天  按天返回
      typeValue = 1
      //小于365天  按月返回
    } else if (timeDiffer >= 15 && timeDiffer <= 60) {// 大于等于15 等于60天  按周返回
      typeValue = 2
      // 大于365天  按年返回
    } else if (timeDiffer >= 61 && timeDiffer <= 365) {// 大于等于61 等于365天  按月返回
      typeValue = 3

    } else if (timeDiffer >= 366 && timeDiffer <= (365 * 3)) {// 大于等于366 等于730天  按季度返回
      typeValue = 4
    } else {// 大于730天 按年返回
      typeValue = 5
    }
    return typeValue
  },
  formatTime(satrtTime) { //自定义请求时间

    let date: any = new Date(satrtTime)
    const YY = date.getFullYear() + '-'
    const MM =
      (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
    const DD = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
    const hh =
      (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
    const mm =
      (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) +
      ':'
    const ss =
      date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
    // return ;
    date = YY + MM + DD + ' ' + hh + mm + ss

    return date

  },
  getDay() {
    const date:any = new Date()
    let base = Date.parse(date) // 转换为时间戳
    const year = date.getFullYear() //获取当前年份
    const mon = date.getMonth() + 1 //获取当前月份
    const day = date.getDate() //获取当前日
    const oneDay = 24 * 3600 * 1000
    console.log(year, mon, day)
    //var daytime = `${year}${mon >= 10 ? mon : '0' + mon}${day >= 10 ? day : '0' + day}`; //今日时间
    //this.$data.daytime = daytime; // 今日时间赋值给变量

    const daytimeArr:any = []
    for (let i = 1; i < 8; i++) { //前七天的时间
      const now: any = new Date(base -= oneDay)
      const myear:any = now.getFullYear()
      const month: any = now.getMonth() + 1
      const mday: any = now.getDate() + 1
      daytimeArr.push([ myear, month >= 10 ? month : '0' + month, mday >= 10 ? mday : '0' + mday ].join('-'))
    }
    return daytimeArr
  }
}

